package com.ct.gd.passport.domain;

import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Scanner;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.CTApp;
import com.ct.gd.passport.common.connect.CtServer;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Protocol;
import com.fuckhtc.gson.Gson;
import com.fuckhtc.gson.annotations.SerializedName;
import com.up91.common.android.connect.Params;

public class PolicyDetail {
	@SerializedName("id")
	private int		catalogId;

	@SerializedName("title")
	private String	title;

	@SerializedName("author")
	private String	author;
	
	@SerializedName("addtime")
	private String	addtime;
	
	@SerializedName("updatetime")
	private String	updatetime;

	@SerializedName("content")
	private String	content;

	public int getCatalogId() {
		return catalogId;
	}

	public String getName() {
		return title;
	}

	public String getAuthor() {
		return author;
	}

	public String getContent() {
		return content;
	}


	public String getTitle() {
		return title;
	}

	public String getAddtime() {
		return addtime;
	}

	public String getUpdatetime() {
		return updatetime;
	}

	public static PolicyDetail load(int catalogId) {
		Params params = new Params();
		params.put(Protocol.Fields.POLICY_CATALOGID, catalogId);
		
		if (Config.ON_LINE) {
			String json = CtServer.getServer().doGet(Protocol.Commands.POLICY_DETAIL, params);
			return new Gson().fromJson(json, PolicyDetail.class);
		}

		PolicyDetail detail = new PolicyDetail();
		detail.catalogId = 1001 ;
		detail.title = "港澳个人旅游";
		detail.author = "Lee";
		detail.content = getMockContent();
		return detail;
	}

	private static String getMockContent() {
		InputStream rawIs = CTApp.getInstance().getResources().openRawResource(R.raw.policy_content);
		try {
			return new Scanner(rawIs).useDelimiter("\\A").next();
		} catch (NoSuchElementException e) {
			e.printStackTrace();
			return "";
		}
	}
}
